CSCI E-92: Application Note 24 Argument passing ---------------- Passing 1 to 6 ints (passingArgs.c) ----------------------------------- void oneArg(int one); void twoArgs(int one, int two); void threeArgs(int one, int two, int three); void fourArgs(int one, int two, int three, int four); void fiveArgs(int one, int two, int three, int four, int five); void sixArgs(int one, int two, int three, int four, int five, int six); int main(void) { oneArg(1); twoArgs(1, 2); threeArgs(1, 2, 3); fourArgs(1, 2, 3, 4); fiveArgs(1, 2, 3, 4, 5); sixArgs(1, 2, 3, 4, 5, 6); return 0; } void oneArg(int one) { } void twoArgs(int one, int two) { } void threeArgs(int one, int two, int three) { } void fourArgs(int one, int two, int three, int four) { } void fiveArgs(int one, int two, int three, int four, int five) { } void sixArgs(int one, int two, int three, int four, int five, int six) { } Disassembly of section .text.main: 00000000
: void threeArgs(int one, int two, int three); void fourArgs(int one, int two, int three, int four); void fiveArgs(int one, int two, int three, int four, int five); void sixArgs(int one, int two, int three, int four, int five, int six); int main(void) { 0: b580 push {r7, lr} 2: b082 sub sp, #8 4: af02 add r7, sp, #8 oneArg(1); 6: f04f 0001 mov.w r0, #1 a: f7ff fffe bl 0
a: R_ARM_THM_CALL oneArg twoArgs(1, 2); e: f04f 0001 mov.w r0, #1 12: f04f 0102 mov.w r1, #2 16: f7ff fffe bl 0
16: R_ARM_THM_CALL twoArgs threeArgs(1, 2, 3); 1a: f04f 0001 mov.w r0, #1 1e: f04f 0102 mov.w r1, #2 22: f04f 0203 mov.w r2, #3 26: f7ff fffe bl 0
26: R_ARM_THM_CALL threeArgs fourArgs(1, 2, 3, 4); 2a: f04f 0001 mov.w r0, #1 2e: f04f 0102 mov.w r1, #2 32: f04f 0203 mov.w r2, #3 36: f04f 0304 mov.w r3, #4 3a: f7ff fffe bl 0
3a: R_ARM_THM_CALL fourArgs fiveArgs(1, 2, 3, 4, 5); 3e: f04f 0305 mov.w r3, #5 42: 9300 str r3, [sp, #0] 44: f04f 0001 mov.w r0, #1 48: f04f 0102 mov.w r1, #2 4c: f04f 0203 mov.w r2, #3 50: f04f 0304 mov.w r3, #4 54: f7ff fffe bl 0
54: R_ARM_THM_CALL fiveArgs sixArgs(1, 2, 3, 4, 5, 6); 58: f04f 0305 mov.w r3, #5 5c: 9300 str r3, [sp, #0] 5e: f04f 0306 mov.w r3, #6 62: 9301 str r3, [sp, #4] 64: f04f 0001 mov.w r0, #1 68: f04f 0102 mov.w r1, #2 6c: f04f 0203 mov.w r2, #3 70: f04f 0304 mov.w r3, #4 74: f7ff fffe bl 0
74: R_ARM_THM_CALL sixArgs return 0; 78: f04f 0300 mov.w r3, #0 } 7c: 4618 mov r0, r3 7e: 46bd mov sp, r7 80: bd80 pop {r7, pc} 82: bf00 nop Passing 1 to 4 non-ints (passingArgsNonInt.c) --------------------------------------------- void oneArg(int *onep); void twoArgs(char one, char two); void threeArgs(long long int one, char two, int *threep); void fourArgs(char one, short int two, int three, long int four); int main(void) { int i; oneArg(&i); twoArgs(1, 2); threeArgs(1, 2, &i); fourArgs(1, 2, 3, 4); return 0; } void oneArg(int *onep) { } void twoArgs(char one, char two) { } void threeArgs(long long int one, char two, int *threep) { } void fourArgs(char one, short int two, int three, long int four) { } Disassembly of section .text.main: 00000000
: void oneArg(int *onep); void twoArgs(char one, char two); void threeArgs(long long int one, char two, int *threep); void fourArgs(char one, short int two, int three, long int four); int main(void) { 0: b580 push {r7, lr} 2: b082 sub sp, #8 4: af00 add r7, sp, #0 int i; oneArg(&i); 6: f107 0304 add.w r3, r7, #4 a: 4618 mov r0, r3 c: f7ff fffe bl 0
c: R_ARM_THM_CALL oneArg twoArgs(1, 2); 10: f04f 0001 mov.w r0, #1 14: f04f 0102 mov.w r1, #2 18: f7ff fffe bl 0
18: R_ARM_THM_CALL twoArgs threeArgs(1, 2, &i); 1c: f107 0304 add.w r3, r7, #4 20: f04f 0001 mov.w r0, #1 24: f04f 0100 mov.w r1, #0 28: f04f 0202 mov.w r2, #2 2c: f7ff fffe bl 0
2c: R_ARM_THM_CALL threeArgs fourArgs(1, 2, 3, 4); 30: f04f 0001 mov.w r0, #1 34: f04f 0102 mov.w r1, #2 38: f04f 0203 mov.w r2, #3 3c: f04f 0304 mov.w r3, #4 40: f7ff fffe bl 0
40: R_ARM_THM_CALL fourArgs return 0; 44: f04f 0300 mov.w r3, #0 } 48: 4618 mov r0, r3 4a: f107 0708 add.w r7, r7, #8 4e: 46bd mov sp, r7 50: bd80 pop {r7, pc} 52: bf00 nop